# coding=utf8
# 全世界最帅的帅哥
from comment.utils.serializers import BaseListSerializer


class ProductListSerializer(BaseListSerializer):
    # 产品列表序列化
    def to_dict(self):
        product_lst = []
        for product in self.data_list:
            product_lst.append(
                {
                    "id": product.proId,
                    "proNum": product.proNum,
                    "minLimit": product.lowerTimeLimit,
                    "maxLimit": product.proUpperInvest,
                    "earning": "年利率" if product.earningType == 134 else "月利率",
                    "returnMoney": "一次性回款" if product.wayToReturnMoney == 109 else "每月部分回款",
                    "closedPeriod": product.closedPeriod,
                    "status": product.status,
                    "proLowerInvest": product.proLowerInvest
                }
            )
        return product_lst


class ProductRateListSerializer(BaseListSerializer):
    # 产品利率的序列化
    def to_dict(self):
        product_rate_dict = {}

        for product_rate in self.data_list:
            product_rate_dict.update(
                {
                    product_rate.month: {
                        "id": product_rate.id,
                        "proId": product_rate.productId,
                        "month": product_rate.month,
                        # 这里是需要转换成float的  不然默认是双精度的 转换不成json格式
                        "incomeRate": float(product_rate.incomeRate)
                    }
                }
            )
        return product_rate_dict